﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 
    /// </summary>
    public class PeerReview
    {
        /// <summary>
        /// 是否开启
        /// </summary>
        /// <returns>数据列表</returns>
        public DataSet GetIsFtatus()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select top 1 * from dbo.t_PeerReview order by FBeginDate desc ");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 开始设定
        /// </summary>
        /// <param name="model">主题Model</param>
        /// <param name="peerReviewID">主题主键ID</param>
        /// <returns>是否开始</returns>
        public bool Satrt(ElingOA6_Admin_DSJCJ.Model.PeerReview model, decimal peerReviewID) 
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update dbo.t_PeerReview set ");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FPeerReviewID=@FPeerReviewID");
            SqlParameter[] parameters = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
                    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FStatus;
            parameters[1].Value = peerReviewID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 结束设定
        /// </summary>
        /// <param name="model">主题Model</param>
        /// <param name="peerReviewID">主题主键ID</param>
        /// <returns>是否结束</returns>
        public bool End(ElingOA6_Admin_DSJCJ.Model.PeerReview model, decimal peerReviewID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update dbo.t_PeerReview set ");
            strSql.Append("FStatus=@FStatus");
            strSql.Append(" where FPeerReviewID=@FPeerReviewID");
            SqlParameter[] parameters = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
                    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FStatus;
            parameters[1].Value = peerReviewID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到主题的主题和编号
        /// </summary>
        /// <returns>数据列表</returns>
        public DataSet GetList() {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 FPeerReviewID,FTitle,FStatus,FBeginDate,FEndDate,FIsVoteIPControl,FIsLookIPControl,FIsSelectAll");
            strSql.Append(" FROM dbo.t_PeerReview ");
            strSql.Append(" order by FBeginDate desc");

            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">主表Model</param>
        /// <param name="peerReviewIPList">IP集合</param>
        /// <param name="peerReviewRuleOptionList">选项集合</param>
        /// <param name="peerReviewRuleList">细则集合（包括得分的选项）</param>
        public void Add(ElingOA6_Admin_DSJCJ.Model.PeerReview model, List<Model.PeerReviewIP> peerReviewIPList, List<Model.PeerReviewRuleOption> peerReviewRuleOptionList, List<Model.PeerReviewRule> peerReviewRuleList)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();

            strSql.Append("insert into dbo.t_PeerReview(");
            strSql.Append("FTitle,FStatus,FBeginDate,FEndDate,FIsVoteIPControl,FIsLookIPControl,FIsSelectAll)");
            strSql.Append(" values (");
            strSql.Append("@FTitle,@FStatus,@FBeginDate,@FEndDate,@FIsVoteIPControl,@FIsLookIPControl,@FIsSelectAll)");
            strSql.Append(";select @returnID=IDENT_CURRENT('dbo.t_PeerReview')");
            SqlParameter[] parameters = {
					new SqlParameter("@FTitle", SqlDbType.NVarChar,200),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FBeginDate", SqlDbType.DateTime),
					new SqlParameter("@FEndDate", SqlDbType.DateTime),
                    new SqlParameter("@FIsVoteIPControl", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsLookIPControl", SqlDbType.NVarChar,1),
                    new SqlParameter("@FIsSelectAll", SqlDbType.NVarChar,1),
                    new SqlParameter("@returnID",SqlDbType.Decimal)};
            parameters[0].Value = model.FTitle;
            parameters[1].Value = model.FStatus;
            parameters[2].Value = model.FBeginDate;
            parameters[3].Value = model.FEndDate;
            parameters[4].Value = model.FIsVoteIPControl;
            parameters[5].Value = model.FIsLookIPControl;
            parameters[6].Value = model.FIsSelectAll;
            parameters[7].Direction = ParameterDirection.Output;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            //添加IP
            if (peerReviewIPList.Count > 0)
            {
                strSql = new StringBuilder();
                strSql.Append("insert into dbo.t_PeerReviewIP(");
                strSql.Append("FIPGroupID,FProp,FPeerReviewID)");
                strSql.Append(" values (");
                strSql.Append("@FIPGroupID,@FProp,@FPeerReviewID)");
                string strSqls = strSql.ToString();
                foreach (Model.PeerReviewIP modelPeerReviewIP in peerReviewIPList) 
                {
                    cmds = new CommandInfo();
                    SqlParameter[] parameters1 = {
					        new SqlParameter("@FIPGroupID", SqlDbType.Int,4),
					        new SqlParameter("@FProp", SqlDbType.NVarChar,20),
					        new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13)};
                    parameters1[0].Value = modelPeerReviewIP.FIPGroupID;
                    parameters1[1].Value = modelPeerReviewIP.FProp;
                    parameters1[2].Direction = ParameterDirection.InputOutput;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters1;
                    cmdList.Add(cmds);
                }
            }

            //添加选项


            if (peerReviewRuleOptionList.Count > 0) 
            {
                strSql = new StringBuilder();
                strSql.Append("insert into dbo.t_PeerReviewRuleOption(");
                strSql.Append("FPeerReviewRuleScoreCd,FScoreName,FDispSeq)");
                strSql.Append(" values (");
                strSql.Append("@FPeerReviewRuleScoreCd,@FScoreName,@FDispSeq)");
               
                string strSqls = strSql.ToString();

                foreach (Model.PeerReviewRuleOption modelPeerReviewRuleOption in peerReviewRuleOptionList)
                {
                    cmds = new CommandInfo();
                    SqlParameter[] parameters2 = {
					            new SqlParameter("@FPeerReviewRuleScoreCd", SqlDbType.NVarChar,20),
					            new SqlParameter("@FScoreName", SqlDbType.NVarChar,30),
					            new SqlParameter("@FDispSeq", SqlDbType.Int,4)};
                    parameters2[0].Value = modelPeerReviewRuleOption.FPeerReviewRuleScoreCd;
                    parameters2[1].Value = modelPeerReviewRuleOption.FScoreName;
                    parameters2[2].Value = modelPeerReviewRuleOption.FDispSeq;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters2;
                    cmdList.Add(cmds);
                }
            }

            //添加细则
            if (peerReviewRuleList.Count > 0) 
            {               
                foreach (Model.PeerReviewRule modelPeerReviewRule in peerReviewRuleList)
                {
                    strSql = new StringBuilder();
                    strSql.Append("insert into dbo.t_PeerReviewRule(");
                    strSql.Append("FPeerReviewRuleCd,FPeerReviewID,FRuleCls,FRuleNote,FDispSeq,FScore)");
                    strSql.Append(" values (");
                    strSql.Append("@FPeerReviewRuleCd,@FPeerReviewID,@FRuleCls,@FRuleNote,@FDispSeq,@FScore)");
                    string strSqls = strSql.ToString();

                    cmds = new CommandInfo();
                    SqlParameter[] parameters3 = {
					            new SqlParameter("@FPeerReviewRuleCd", SqlDbType.NVarChar,20),
					            new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13),
					            new SqlParameter("@FRuleCls", SqlDbType.NVarChar,20),
					            new SqlParameter("@FRuleNote", SqlDbType.NVarChar,-1),
					            new SqlParameter("@FDispSeq", SqlDbType.Int,4),
					            new SqlParameter("@FScore", SqlDbType.Int,4)};
                    parameters3[0].Value = modelPeerReviewRule.FPeerReviewRuleCd;
                    parameters3[1].Direction = ParameterDirection.InputOutput;
                    parameters3[2].Value = modelPeerReviewRule.FRuleCls;
                    parameters3[3].Value = modelPeerReviewRule.FRuleNote;
                    parameters3[4].Value = modelPeerReviewRule.FDispSeq;
                    parameters3[5].Value = modelPeerReviewRule.FScore;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters3;
                    cmdList.Add(cmds);

                    //添加分数
                    List<Model.PeerReviewRuleScore> PeerReviewRuleScoreList = modelPeerReviewRule.PeerReviewRuleScoreList;

                    strSql = new StringBuilder();
                    strSql.Append("insert into dbo.t_PeerReviewRuleScore(");
                    strSql.Append("FPeerReviewRuleCd,FPeerReviewID,FPeerReviewRuleScoreCd,FScore)");
                    strSql.Append(" values (");
                    strSql.Append("@FPeerReviewRuleCd,@FPeerReviewID,@FPeerReviewRuleScoreCd,@FScore)");
                    strSqls = strSql.ToString();

                    foreach (Model.PeerReviewRuleScore modelPeerReviewRuleScore in PeerReviewRuleScoreList) 
                    {
                        cmds = new CommandInfo();
                        SqlParameter[] parameters4 = {
					                new SqlParameter("@FPeerReviewRuleCd", SqlDbType.NVarChar,20),
					                new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13),
					                new SqlParameter("@FPeerReviewRuleScoreCd", SqlDbType.NVarChar,20),
					                new SqlParameter("@FScore", SqlDbType.Int,4)};
                        parameters4[0].Value = modelPeerReviewRule.FPeerReviewRuleCd;
                        parameters4[1].Direction = ParameterDirection.InputOutput;
                        parameters4[2].Value = modelPeerReviewRuleScore.FPeerReviewRuleScoreCd;
                        parameters4[3].Value = modelPeerReviewRuleScore.FScore;

                        cmds.CommandText = strSqls;
                        cmds.Parameters = parameters4;
                        cmdList.Add(cmds);
                    }                    
                }            
            }


            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model">主表Model</param>
        /// <param name="peerReviewIPList">IP集合</param>
        /// <param name="peerReviewRuleOptionList">选项集合</param>
        /// <param name="peerReviewRuleList">细则集合（包括得分的选项）</param>
        public void Update(ElingOA6_Admin_DSJCJ.Model.PeerReview model, List<Model.PeerReviewIP> peerReviewIPList, List<Model.PeerReviewRuleOption> peerReviewRuleOptionList, List<Model.PeerReviewRule> peerReviewRuleList)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();

            strSql.Append("update dbo.t_PeerReview set ");
            strSql.Append("FTitle=@FTitle,");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FBeginDate=@FBeginDate,");
            strSql.Append("FEndDate=@FEndDate,");
            strSql.Append("FIsVoteIPControl=@FIsVoteIPControl,");
            strSql.Append("FIsLookIPControl=@FIsLookIPControl,");
            strSql.Append("FIsSelectAll=@FIsSelectAll");
            strSql.Append(" where FPeerReviewID=@FPeerReviewID");
            string strSqls = strSql.ToString();
            SqlParameter[] parameters = {
					new SqlParameter("@FTitle", SqlDbType.NVarChar,200),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FBeginDate", SqlDbType.DateTime),
					new SqlParameter("@FEndDate", SqlDbType.DateTime),
                    new SqlParameter("@FIsVoteIPControl", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsLookIPControl", SqlDbType.NVarChar,1),
                    new SqlParameter("@FIsSelectAll", SqlDbType.NVarChar,1),
					new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FTitle;
            parameters[1].Value = model.FStatus;
            parameters[2].Value = model.FBeginDate;
            parameters[3].Value = model.FEndDate;
            parameters[4].Value = model.FIsVoteIPControl;
            parameters[5].Value = model.FIsLookIPControl;
            parameters[6].Value = model.FIsSelectAll;
            parameters[7].Value = model.FPeerReviewID;

            cmds.CommandText = strSqls;
            cmds.Parameters = parameters;
            cmdList.Add(cmds);



            ///IP组
            strSql = new StringBuilder();
            cmds = new CommandInfo();
            strSql.Append("delete from dbo.t_PeerReviewIP where FPeerReviewID=@FPeerReviewID");
            SqlParameter[] parameters2 = { 
                    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13) };
            parameters2[0].Value = model.FPeerReviewID;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);
            
            if (peerReviewIPList.Count > 0)
            {
                strSql = new StringBuilder();
                strSql.Append("insert into dbo.t_PeerReviewIP(");
                strSql.Append("FProp,FPeerReviewID,FIPGroupID)");
                strSql.Append(" values (");
                strSql.Append("@FProp,@FPeerReviewID,@FIPGroupID)");

                strSqls = strSql.ToString();

                foreach (Model.PeerReviewIP modelPeerReviewIP in peerReviewIPList)
                {
                    cmds = new CommandInfo();
                    SqlParameter[] parameters8 = {
					    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13),
					    new SqlParameter("@FProp", SqlDbType.NVarChar,20),
					    new SqlParameter("@FIPGroupID", SqlDbType.Int,4)};
                    parameters8[0].Value = model.FPeerReviewID;
                    parameters8[1].Value = modelPeerReviewIP.FProp;
                    parameters8[2].Value = modelPeerReviewIP.FIPGroupID;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters8;
                    cmdList.Add(cmds);
                }

            }

            
            //删除选项

            strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_PeerReviewRuleOption ");
            cmds = new CommandInfo();       
            SqlParameter[] abc = { new SqlParameter() };
            cmds.Parameters = abc;
            cmds.CommandText = strSql.ToString();
            cmdList.Add(cmds);

            //增加选项
            if (peerReviewRuleOptionList.Count() > 0) 
            {
                strSql = new StringBuilder();

                strSql.Append("insert into dbo.t_PeerReviewRuleOption(");
                strSql.Append("FPeerReviewRuleScoreCd,FScoreName,FDispSeq)");
                strSql.Append(" values (");
                strSql.Append("@FPeerReviewRuleScoreCd,@FScoreName,@FDispSeq)");

                strSqls = strSql.ToString();

                foreach (Model.PeerReviewRuleOption modelPeerReviewRuleOption in peerReviewRuleOptionList)
                {
                    cmds = new CommandInfo();
                    SqlParameter[] parameters3 = {
					            new SqlParameter("@FPeerReviewRuleScoreCd", SqlDbType.NVarChar,20),
					            new SqlParameter("@FScoreName", SqlDbType.NVarChar,30),
					            new SqlParameter("@FDispSeq", SqlDbType.Int,4)};
                    parameters3[0].Value = modelPeerReviewRuleOption.FPeerReviewRuleScoreCd;
                    parameters3[1].Value = modelPeerReviewRuleOption.FScoreName;
                    parameters3[2].Value = modelPeerReviewRuleOption.FDispSeq;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters3;
                    cmdList.Add(cmds);
                }
            
            }
            if (peerReviewRuleList.Count() > 0)
            {
                //删除分数
                strSql = new StringBuilder();
                strSql.Append("delete from dbo.t_PeerReviewRuleScore where FPeerReviewID=@FPeerReviewID");

                strSqls = strSql.ToString();
                cmds = new CommandInfo();
                SqlParameter[] parameters5 = { 
                    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13) };
                parameters5[0].Value = model.FPeerReviewID;

                cmds.CommandText = strSqls;
                cmds.Parameters = parameters5;
                cmdList.Add(cmds);


                //删除细则

                strSql = new StringBuilder();
                strSql.Append("delete from dbo.t_PeerReviewRule where FPeerReviewID=@FPeerReviewID");

                strSqls = strSql.ToString();
                cmds = new CommandInfo();
                SqlParameter[] parameters4 = { 
                    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13) };
                parameters4[0].Value = model.FPeerReviewID;

                cmds.CommandText = strSqls;
                cmds.Parameters = parameters4;
                cmdList.Add(cmds);

                //添加细则
            
                foreach (Model.PeerReviewRule modelPeerReviewRule in peerReviewRuleList)
                {
                    strSql = new StringBuilder();
                    strSql.Append("insert into dbo.t_PeerReviewRule(");
                    strSql.Append("FPeerReviewRuleCd,FPeerReviewID,FRuleCls,FRuleNote,FDispSeq,FScore)");
                    strSql.Append(" values (");
                    strSql.Append("@FPeerReviewRuleCd,@FPeerReviewID,@FRuleCls,@FRuleNote,@FDispSeq,@FScore)");
                    strSqls = strSql.ToString();

                    cmds = new CommandInfo();
                    SqlParameter[] parameters6 = {
					            new SqlParameter("@FPeerReviewRuleCd", SqlDbType.NVarChar,20),
					            new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13),
					            new SqlParameter("@FRuleCls", SqlDbType.NVarChar,20),
					            new SqlParameter("@FRuleNote", SqlDbType.NVarChar,-1),
					            new SqlParameter("@FDispSeq", SqlDbType.Int,4),
					            new SqlParameter("@FScore", SqlDbType.Int,4)};
                    parameters6[0].Value = modelPeerReviewRule.FPeerReviewRuleCd;
                    parameters6[1].Value = model.FPeerReviewID;
                    parameters6[2].Value = modelPeerReviewRule.FRuleCls;
                    parameters6[3].Value = modelPeerReviewRule.FRuleNote;
                    parameters6[4].Value = modelPeerReviewRule.FDispSeq;
                    parameters6[5].Value = modelPeerReviewRule.FScore;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters6;
                    cmdList.Add(cmds);

                    //添加分数
                    List<Model.PeerReviewRuleScore> PeerReviewRuleScoreList = modelPeerReviewRule.PeerReviewRuleScoreList;

                    strSql = new StringBuilder();
                    strSql.Append("insert into dbo.t_PeerReviewRuleScore(");
                    strSql.Append("FPeerReviewRuleCd,FPeerReviewID,FPeerReviewRuleScoreCd,FScore)");
                    strSql.Append(" values (");
                    strSql.Append("@FPeerReviewRuleCd,@FPeerReviewID,@FPeerReviewRuleScoreCd,@FScore)");
                    strSqls = strSql.ToString();

                    foreach (Model.PeerReviewRuleScore modelPeerReviewRuleScore in PeerReviewRuleScoreList)
                    {
                        cmds = new CommandInfo();
                        SqlParameter[] parameters7 = {
					                new SqlParameter("@FPeerReviewRuleCd", SqlDbType.NVarChar,20),
					                new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13),
					                new SqlParameter("@FPeerReviewRuleScoreCd", SqlDbType.NVarChar,20),
					                new SqlParameter("@FScore", SqlDbType.Int,4)};
                        parameters7[0].Value = modelPeerReviewRule.FPeerReviewRuleCd;
                        parameters7[1].Value = model.FPeerReviewID;
                        parameters7[2].Value = modelPeerReviewRuleScore.FPeerReviewRuleScoreCd;
                        parameters7[3].Value = modelPeerReviewRuleScore.FScore;

                        cmds.CommandText = strSqls;
                        cmds.Parameters = parameters7;
                        cmdList.Add(cmds);
                    }
                }
            }
            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }

        /// <summary>
        /// 有评议结果是的更新方法
        /// </summary>
        /// <param name="model">主表的model</param>
        /// <param name="peerReviewIPList">IP集合</param>
        /// <param name="peerReviewRuleOptionList">选项集合</param>
        public void UpdateTwoList(ElingOA6_Admin_DSJCJ.Model.PeerReview model, List<Model.PeerReviewIP> peerReviewIPList, List<Model.PeerReviewRuleOption> peerReviewRuleOptionList)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();

            strSql.Append("update dbo.t_PeerReview set ");
            strSql.Append("FTitle=@FTitle,");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FBeginDate=@FBeginDate,");
            strSql.Append("FEndDate=@FEndDate,");
            strSql.Append("FIsVoteIPControl=@FIsVoteIPControl,");
            strSql.Append("FIsLookIPControl=@FIsLookIPControl");
            strSql.Append(" where FPeerReviewID=@FPeerReviewID");
            string strSqls = strSql.ToString();
            SqlParameter[] parameters = {
					new SqlParameter("@FTitle", SqlDbType.NVarChar,200),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,1),
					new SqlParameter("@FBeginDate", SqlDbType.DateTime),
					new SqlParameter("@FEndDate", SqlDbType.DateTime),
                    new SqlParameter("@FIsVoteIPControl", SqlDbType.NVarChar,1),
					new SqlParameter("@FIsLookIPControl", SqlDbType.NVarChar,1),
					new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13)};
            parameters[0].Value = model.FTitle;
            parameters[1].Value = model.FStatus;
            parameters[2].Value = model.FBeginDate;
            parameters[3].Value = model.FEndDate;
            parameters[4].Value = model.FIsVoteIPControl;
            parameters[5].Value = model.FIsLookIPControl;
            parameters[6].Value = model.FPeerReviewID;

            cmds.CommandText = strSqls;
            cmds.Parameters = parameters;
            cmdList.Add(cmds);



            ///IP组
            strSql = new StringBuilder();
            cmds = new CommandInfo();
            strSql.Append("delete from dbo.t_PeerReviewIP where FPeerReviewID=@FPeerReviewID");
            SqlParameter[] parameters2 = { 
                    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13) };
            parameters2[0].Value = model.FPeerReviewID;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);

            if (peerReviewIPList.Count > 0)
            {
                strSql = new StringBuilder();
                strSql.Append("insert into dbo.t_PeerReviewIP(");
                strSql.Append("FProp,FPeerReviewID,FIPGroupID)");
                strSql.Append(" values (");
                strSql.Append("@FProp,@FPeerReviewID,@FIPGroupID)");

                strSqls = strSql.ToString();

                foreach (Model.PeerReviewIP modelPeerReviewIP in peerReviewIPList)
                {
                    cmds = new CommandInfo();
                    SqlParameter[] parameters8 = {
					    new SqlParameter("@FPeerReviewID", SqlDbType.Decimal,13),
					    new SqlParameter("@FProp", SqlDbType.NVarChar,20),
					    new SqlParameter("@FIPGroupID", SqlDbType.Int,4)};
                    parameters8[0].Value = model.FPeerReviewID;
                    parameters8[1].Value = modelPeerReviewIP.FProp;
                    parameters8[2].Value = modelPeerReviewIP.FIPGroupID;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters8;
                    cmdList.Add(cmds);
                }

            }


            //删除选项

            strSql = new StringBuilder();
            strSql.Append("delete from dbo.t_PeerReviewRuleOption ");
            cmds = new CommandInfo();
            SqlParameter[] abc = { new SqlParameter() };
            cmds.Parameters = abc;
            cmds.CommandText = strSql.ToString();
            cmdList.Add(cmds);

            //增加选项
            if (peerReviewRuleOptionList.Count() > 0)
            {
                strSql = new StringBuilder();

                strSql.Append("insert into dbo.t_PeerReviewRuleOption(");
                strSql.Append("FPeerReviewRuleScoreCd,FScoreName,FDispSeq)");
                strSql.Append(" values (");
                strSql.Append("@FPeerReviewRuleScoreCd,@FScoreName,@FDispSeq)");

                strSqls = strSql.ToString();

                foreach (Model.PeerReviewRuleOption modelPeerReviewRuleOption in peerReviewRuleOptionList)
                {
                    cmds = new CommandInfo();
                    SqlParameter[] parameters3 = {
					            new SqlParameter("@FPeerReviewRuleScoreCd", SqlDbType.NVarChar,20),
					            new SqlParameter("@FScoreName", SqlDbType.NVarChar,30),
					            new SqlParameter("@FDispSeq", SqlDbType.Int,4)};
                    parameters3[0].Value = modelPeerReviewRuleOption.FPeerReviewRuleScoreCd;
                    parameters3[1].Value = modelPeerReviewRuleOption.FScoreName;
                    parameters3[2].Value = modelPeerReviewRuleOption.FDispSeq;

                    cmds.CommandText = strSqls;
                    cmds.Parameters = parameters3;
                    cmdList.Add(cmds);
                }

            }
           
            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }


    }
}
